<template>
<div class="tc-left pr10 fl">
    <ul class="clearfix uiTab1 mb5 j_outerHeight">
        <!-- <router-link tag="li" class="col-md-4 fl" to="/projectFiles/scene"><a href="javascript:">项</a></router-link>
        <router-link tag="li" class="col-md-4 fl uiTab1-active" to="/projectFiles/SceneLibrary"><a href="javascript:">现场库</a></router-link> -->
    </ul>
    <div class="daily_title j_outerHeight">
        <ul class="clearfix">
            <router-link tag="li"  to="/projectFiles/ServerProject" active-class="title_cur" data-title="全部">全</router-link>
            <span aria-hidden="true" class="iconfont icon-add icon-2x bold pointer cBlue fr mt2 mr5" @click="addPage()" data-title="添加"></span>
        </ul>
    </div>
    <div class="contentbox">
        <table class="uiTable j_outerHeight">
            <thead>
                <tr>
                    <th width="15%">编号</th>
                    <th width="20%" class="tx-center">编号</th>
                    <th width="30%" class="tx-center">名称</th>
                    <th width="20%" class="tx-center">状态</th>
                    <th width="15%">开关</th>
                </tr>
            </thead>
        </table>
        <div class="scroll-content thinScroll thinScroll-table" v-loading="loading" v-scrollHeight="36">
            <table class="uiTable uiTable-striped uiTable-hover" id="tab1">
                <tbody>
                    <tr v-for="(item,index) in itemList" :key="index" :class="{'tractive':index == trIndex}" @click="siderBarTrclick(index,item)">
                        <td width="15%" class="relative">{{index+1}}</td>
                        <td width="20%" :data-title='item.code' >{{item.code | truncate(3)}}</td>
                        <td width="30%" :data-title='item.name'>{{item.name | truncate(5)}}</td>
                        <td width="15%">---</td>
                        <td width="15%">{{item.delFlag ===1 ?'关闭':'开启'}}</td>
                    </tr>
                </tbody>
            </table>
        </div>
        <div class="j_outerHeight clearfix tj_bottom">
            <p class="col-md-3" data-title="全部">{{allCount}}</p>
            <p class="col-md-3 cGreen" data-title="正常">{{zcCount}}</p>
            <p class="col-md-3 cOrange" data-title="异常">{{ycCount}}</p>
            <p class="col-md-3 cRed" data-title="问题">{{wtCount}}</p>
        </div>
    </div>
</div>
</template>
<script>
import { mapMutations, mapGetters } from 'vuex'
import { getSubject } from '../Resources/Api/index'
export default {
    data () {
        return {
            loading: false,
            trIndex: 0,
            itemList: [], // 服务项集合
            allCount: 0,
            zcCount: 0,
            ycCount: 0,
            wtCount: 0
        }
    },
    computed: {
        ...mapGetters(['leftInfo', 'updatePlate'])
    },
    created () {
        this.load()
    },
    methods: {

        ...mapMutations({
            setLeftData: `SET_LEFT_INFO`
        }),
        // 点击 + 号二段弹窗页面
        addPage () {
            this.$router.push('/projectFiles/ServerSubject/addPage')
        },
        siderBarTrclick (index, item) {
            this.trIndex = index
            // 保存字段时 一定要确认公共字段一致
            this.setLeftData(item)
            // 关闭弹窗
            this.$router.push(this.$route.matched[1].path)
        },
        load () {
            this.trIndex = 0
            // 用_this 代替this
            let _this = this
            _this.loading = true
            let params = {}
            // 接口获取数据，对项目阶段进行转换
            getSubject(params).then(results => {
                if (results.data.StatusCode === 1) {
                    _this.itemList = results.data.Body.subjectList
                    this.siderBarTrclick(this.trIndex, _this.itemList[this.trIndex])
                    this.updateBottom()
                }
            }).catch(error => {
                console.log(error)
            })

            _this.loading = false
        },
        // 更新底部正常异常问题的数量
        updateBottom () {
            let zcCount = 0
            let ycCount = 0
            let wtCount = 0
            this.allCount = this.itemList.length
            this.zcCount = zcCount
            this.ycCount = ycCount
            this.wtCount = wtCount
        }
    },
    watch: {
        updatePlate () {
            this.load()
        }
    }
}
</script>
